package com.lxlg.lxlg_order.common.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;



public class TokenUtil {
//    @Resource
//    private static JwtProperties jp;
    public static String getUserPhone(){
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("UserToken");
        if(null==token){
            return "18875138039";
        }
        return ((String) JwtUtil.parseToken(token).get("userPhone"));
    }

    public static Integer getUserId(){
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("UserToken");
        if(null==token){
            return 4;
        }
        return  ((Integer) JwtUtil.parseToken(token).get("userId"));
    }

    public static String getUserName(){
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("UserToken");
        if(null==token){
            return "可可";
        }
        return ((String) JwtUtil.parseToken(token).get("userName"));
    }
}
